import logging
import sys
import time


def args_to_single_string(args):
    if len(args) == 0:
        return ''
    try:
        output = []
        for i in args:
            output.append(str(i))
        return '  '.join(output)
    except Exception as e:
        return "深度太大，跟踪不了" + type(args)


class Logger:
    def __init__(self, name):
        self.log = logging.getLogger(name)
        self.name = name
        self.log.setLevel(logging.INFO)
        self.log_handler = logging.StreamHandler(sys.stdout)
        # print(self.log.handlers)
        self.log.addHandler(self.log_handler)
    @staticmethod
    def get_line_number():
        return  sys._getframe().f_lineno
    def info(self, msg, *args):
        self.log.info(f'{self.name} :{self.get_line_number()} info ：{msg} :  {args_to_single_string(args)} ')

    def debug(self, msg, *args):
        self.log.debug(f'{self.name}:{self.get_line_number()} {msg} :  {args_to_single_string(args)} ')

    def warning(self, msg, *args):
        self.log.warning(f'{self.name}:{self.get_line_number()} {msg} :  {args_to_single_string(args)} ')

    def error(self, msg, *args):
        self.log.error(f'{self.name}:{self.get_line_number()} {msg} :  {args_to_single_string(args)} ')


if __name__ == '__main__':
    a = Logger('a')

    for i in range(100):
        a.info("你好", i, 4, 5)
